#
#
#   A file which opens a neuroConstruct project, changes the value of the 
#   amplitude in the electrical stimulation to a random value, then saves the project
#
#   Author: Padraig Gleeson
#
#   This file has been developed as part of the neuroConstruct project
#   This work has been funded by the Medical Research Council and the
#   Wellcome Trust
#
#

try:
	from java.io import File
	from java.lang import System
except ImportError:
	print "Note: this file should be run using ..\\nC.bat -python XXX.py' or './nC.sh -python XXX.py'"
	print "See http://www.neuroconstruct.org/docs/python.html for more details"
	quit()

from ucl.physiol.neuroconstruct.project import ProjectManager
from ucl.physiol.neuroconstruct.project.packing import SinglePositionedCellPackingAdapter

from math import *
from random import *

import sys
from time import *


def testAll(argv=None):
    if argv is None:
        argv = sys.argv

    # Load an existing neuroConstruct project
    projFile = File("../CElegans.ncx")
    print "Loading project from file: " + projFile.getAbsolutePath()+", exists: "+ str(projFile.exists())

    pm = ProjectManager()
    myProject = pm.loadProject(projFile)
    print "Loaded project: " + myProject.getProjectName()


    defSimConfig = myProject.simConfigInfo.getDefaultSimConfig()

    expectedNumberCells = 302


    ##########################

    print "Test 1: number of cells..."


    pm.doGenerate(defSimConfig.getName(), 1234)

    while pm.isGenerating():
            print "Waiting for the project to be generated with Simulation Configuration: "+str(defSimConfig)
            sleep(1)

    numGenerated = myProject.generatedCellPositions.getNumberInAllCellGroups()

    print "Number of cells generated: " + str(numGenerated)

    assert numGenerated == expectedNumberCells

    print "Correct number of cells generated!"

    ##########################



if __name__ == "__main__":
    testAll()
